package com.gql;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * description: CodeGet mp代码生成器
 * @author: gql
 * @date: 2021/10
 */
public class CodeGenerator {
    public static void main(String[] args) {

        // 1.创建代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 2.全局配置
        GlobalConfig gc = new GlobalConfig();
        //String projectPath = System.getProperty("user.dir");
        String projectPath = "E:\\IntelliJ_IDEA\\my_workspace\\hospitals";
        String moduleDir = "\\service\\service_order";// 必改点1
        String packageDir = "/src/main/java";
        gc.setOutputDir(projectPath + moduleDir + packageDir);
        //去掉Service接口的首字母I
        gc.setServiceName("%sService");
        gc.setAuthor("gql");
        gc.setOpen(false);
        // 是否生成swagger注解
        gc.setSwagger2(false);
        mpg.setGlobalConfig(gc);

        // 3、数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://192.168.28.129:3306/yygh_order?characterEncoding=utf-8&useSSL=false");// 必改点2
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");
        dsc.setDbType(DbType.MYSQL);
        mpg.setDataSource(dsc);

        // 4、包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.xipu.yygh");// 必改点3
        pc.setModuleName("order");// 必改点4
        pc.setController("controller");
        pc.setEntity("entity");
        pc.setService("service");
        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);

        // 5、策略配置
        StrategyConfig strategy = new StrategyConfig();
        // 指定表
        strategy.setInclude("refund_info");// 必改点5
        //数据库表映射到实体的命名策略
        strategy.setNaming(NamingStrategy.underline_to_camel);
        //数据库表字段映射到实体的命名策略
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        // lombok 模型 @Accessors(chain = true) setter链式操作
        strategy.setEntityLombokModel(true);
        //restful api风格控制器
        strategy.setRestControllerStyle(true);
        //url中驼峰转连字符
        strategy.setControllerMappingHyphenStyle(true);
        // 继承BaseEntity
        //strategy.setSuperEntityClass(BaseEntity.class);
        // 开启TableField注解
        //strategy.setEntityTableFieldAnnotationEnable(true);

        mpg.setStrategy(strategy);

        // 6、执行
        mpg.execute();
    }
}
